package cn.pangza.web.exception;

import cn.pangza.web.utils.ResponseData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler({RuntimeException.class})
    public ResponseData<Object> runTimeException(RuntimeException runtimeException) {
        runtimeException.printStackTrace();
        return ResponseData.error(runtimeException.getMessage());
    }

    @ExceptionHandler({BusinessException.class})
    public ResponseData<Object> runTimeException(BusinessException exception) {
        exception.printStackTrace();
        return ResponseData.error(exception.getMessage());
    }

    @ExceptionHandler({Exception.class})
    public ResponseData<Object> exception(Exception exception) {
        exception.printStackTrace();
        return ResponseData.error(exception.getMessage());
    }


}
